package com.cbg.archives.controller;

import com.cbg.archives.dto.ArchivesModularDTO;
import com.cbg.archives.dto.EsArchivesDTO;
import com.cbg.archives.service.IArchivesService;
import com.cbg.archives.vo.ArchivesVO;
import com.cbg.archives.vo.ModularDirectionsVO;
import com.cbg.archives.vo.ModularVO;
import com.cbg.archives.vo.SelectedModularVO;
import com.cbg.dto.SelectedColListDTO;
import com.cbg.vo.CategoryNameVO;
import com.cbg.vo.DirectionsVO;
import com.shuyuwl.core.support.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 档案管理Controller
 *
 * @author wangjuzheng
 * @date 2019-10-24
 */
@RestController
@Api(tags = "全景通查-档案管理")
@RequestMapping("/api/archives")
@CrossOrigin(allowCredentials = "true", maxAge = 3600, allowedHeaders = "*", origins = "*")
public class ArchivesController {

    @Resource
    private IArchivesService archivesService;

    /**
     * 获取全部的分类信息
     *
     * @return 全部的分类信息
     */
    @GetMapping(value = "/category/list")
    @ApiOperation(value = "全部的分类信息")
    public ServerResponse<List<EsArchivesDTO>> getCategoryList() {

        //获取分类信息
        List<EsArchivesDTO> list = archivesService.getArchivesList();
        return ServerResponse.createBySuccess(list);
    }

    /**
     * 分类位置的移动
     *
     * @param directionsVO 移动VO
     * @return 模型
     */
    @PutMapping(value = "/category/directions")
    @ApiOperation(value = "分类位置的移动")
    public ServerResponse updateCategoryDirections(@Validated @RequestBody DirectionsVO directionsVO) {

        //分类位置的移动
        archivesService.updateArchivesDirections(directionsVO);
        return ServerResponse.createBySuccess("移动成功");
    }

    /**
     * 修改后的分类信息
     *
     * @param categoryNameVO 更新名称vo
     * @return 修改后的分页信息
     */
    @PutMapping(value = "/category/name")
    @ApiOperation(value = "分类名称的修改")
    public ServerResponse<EsArchivesDTO> updateCategoryName(@Validated @RequestBody CategoryNameVO categoryNameVO) {

        //分类名称的修改
        EsArchivesDTO esArchivesDTO = archivesService.updateArchivesName(categoryNameVO.getId(), categoryNameVO.getName());
        return ServerResponse.createBySuccess(esArchivesDTO);
    }

    /**
     * 分类的删除
     *
     * @param archivesId 分类id
     * @return 模型
     */
    @DeleteMapping(value = "/category/{archivesId}")
    @ApiOperation(value = "分类的删除")
    public ServerResponse deleteArchives(@PathVariable Long archivesId) {

        //删除分类
        archivesService.deleteArchives(archivesId);
        return ServerResponse.createBySuccess("删除成功");
    }

    /**
     * 分类的添加
     *
     * @param archivesVO 分类VO
     * @return 分类添加的信息
     */
    @PostMapping("/category")
    @ApiOperation(value = "分类的添加")
    public ServerResponse<EsArchivesDTO> addArchives(@Validated @RequestBody ArchivesVO archivesVO) {

        //个人档案分类的添加
        EsArchivesDTO esArchivesDTO = archivesService.addArchives(archivesVO);
        return ServerResponse.createBySuccess(esArchivesDTO);
    }

    /**
     * 模块列表信息的获取
     *
     * @param archivesId 模块id
     * @return 分类下的模块信息
     */
    @GetMapping(value = "/modular/list/{archivesId}")
    @ApiOperation(value = "模块列表信息的获取")
    public ServerResponse<List<ArchivesModularDTO>> getModularList(@ApiParam(value = "分类id") @PathVariable Long archivesId) {

        //根据分类id获取模块信息
        List<ArchivesModularDTO> list = archivesService.getModular(archivesId);
        return ServerResponse.createBySuccess(list);
    }

    /**
     * 添加模块
     *
     * @param modularVO 模块参数DTO
     * @return 模型
     */
    @PostMapping(value = "/modular")
    @ApiOperation(value = "添加模块信息")
    public ServerResponse addModular(@Validated @RequestBody ModularVO modularVO) {

        //添加模块信息
        archivesService.addModular(modularVO);
        return ServerResponse.createBySuccess("添加成功");
    }

    /**
     * 模块位置的移动
     *
     * @param directionsVO 个人档案模块位置移动VO
     * @return 模型
     */
    @PutMapping(value = "/modular/directions")
    @ApiOperation(value = "模块位置的移动")
    public ServerResponse updateModularDirections(@Validated @RequestBody ModularDirectionsVO directionsVO) {

        //个人档案模块位置的移动
        archivesService.updateModularDirections(directionsVO.getArchivesId(), directionsVO.getModularId(),
                directionsVO.getDirectionType());
        return ServerResponse.createBySuccess("移动成功");
    }

    /**
     * 模块的删除
     *
     * @param modularId 模块id
     * @return 模型
     */
    @DeleteMapping(value = "/modular/{modularId}")
    @ApiOperation(value = "删除模块信息")
    public ServerResponse deleteModular(@ApiParam(value = "模块id") @PathVariable Long modularId) {

        //删除模块信息
        archivesService.deleteModular(modularId);
        return ServerResponse.createBySuccess("模块删除成功");
    }

    /**
     * 模块的更新
     *
     * @param modularVO 模块参数
     * @return 模型
     */
    @PutMapping(value = "/modular")
    @ApiOperation(value = "模块的更新")
    public ServerResponse updateModular(@Validated @RequestBody ModularVO modularVO) {

        //模块的更新
        archivesService.updateModular(modularVO);
        return ServerResponse.createBySuccess("更新成功");
    }

    /**
     * 获取模块下的列信息（根据模块id和表id获取列信息）
     *
     * @param selectedModularVO 模块列参数模型
     * @return 模型
     */
    @GetMapping(value = "/modular/col/list")
    @ApiOperation(value = "获取模块下的列信息")
    public ServerResponse<List<SelectedColListDTO>> selectedModular(@Validated SelectedModularVO selectedModularVO) {

        //获取模块下的列信息（根据模块id和表id获取列信息）
        List<SelectedColListDTO> list = archivesService.selectedModular(selectedModularVO.getModularId(), selectedModularVO.getTableId());
        return ServerResponse.createBySuccess(list);
    }
}
